/********************************************************************************
  * @file     SD93F115B_rtc.h
  * @author   TEST TEAM 													    	
  * @version  v0															    	
  * @date     Septemper 2022												    	
  * @brief   
  *           
  * Copyright (C) 2022  Hangzhou SDIC Microelectronics Co., Ltd
******************************************************************************/


/* Define to prevent recursive inclusion */
#ifndef __SD93F115B_RTC_H
#define __SD93F115B_RTC_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes */

#include "SD93F115B.h"

/*********************RTC_Hour_Format**************************/ 
#define RTC_HourFormat_24                    ((uint8_t)0x80)
#define RTC_HourFormat_12                    ((uint8_t)0x00)

#define IS_RTC_Hour_Format(Format) (((Format) == RTC_HourFormat_24)||((Format) == RTC_HourFormat_12))

#define RTC_H12_AM                           ((uint8_t)0x00)
#define RTC_H12_PM                           ((uint8_t)0x20)
#define IS_RTC_H12(Format) (((Format) == RTC_H12_AM) || ((Format) == RTC_H12_PM))
	
#define IS_RTC_Hour12(Hour)            (((Hour) > 0) && ((Hour) <= 0x12))
#define IS_RTC_Hour24(Hour)            	((Hour) <= 0x23)
#define IS_RTC_Minutes(Minutes)       	((Minutes) <= 0x59)
#define IS_RTC_Seconds(Seconds)        	((Seconds) <= 0x59)

/***************** RTC_Year_Date_Definitions ***********************/ 
#define IS_RTC_Year(Year)              	((Year) <= 0x99)

/*************** RTC_Month_Date_Definitions ************************/ 
#define RTC_Month_January              	((uint8_t)0x01)
#define RTC_Month_February             	((uint8_t)0x02)
#define RTC_Month_March                	((uint8_t)0x03)
#define RTC_Month_April                	((uint8_t)0x04)
#define RTC_Month_May                  	((uint8_t)0x05)
#define RTC_Month_June                 	((uint8_t)0x06)
#define RTC_Month_July                 	((uint8_t)0x07)
#define RTC_Month_August               	((uint8_t)0x08)
#define RTC_Month_September            	((uint8_t)0x09)
#define RTC_Month_October              	((uint8_t)0x10)
#define RTC_Month_November             	((uint8_t)0x11)
#define RTC_Month_December             	((uint8_t)0x12)

#define IS_RTC_Month(Month)            	(((Month) >= 0x01) && ((Month) <=0x12))
#define IS_RTC_Date(Date)               (((Date) >= 0x01) && ((Date) <=0x31))

/********************* RTC_WeekDay_Definitions *********************/ 
  
#define	RTC_Weekday_Monday             	((uint8_t)0x01)
#define	RTC_Weekday_Tuesday            	((uint8_t)0x02)
#define	RTC_Weekday_Wednesday          	((uint8_t)0x03)
#define	RTC_Weekday_Thursday           	((uint8_t)0x04)
#define	RTC_Weekday_Friday             	((uint8_t)0x05)
#define	RTC_Weekday_Saturday           	((uint8_t)0x06)
#define	RTC_Weekday_Sunday             	((uint8_t)0x07)

#define IS_RTC_Weekday(Day) (((Day) == RTC_Weekday_Monday)   ||\
							 ((Day) == RTC_Weekday_Tuesday)  ||\
							 ((Day) == RTC_Weekday_Wednesday)||\
							 ((Day) == RTC_Weekday_Thursday) ||\
							 ((Day) == RTC_Weekday_Friday)   ||\
							 ((Day) == RTC_Weekday_Saturday) ||\
							 ((Day) == RTC_Weekday_Sunday))
							 
/**********************RTC_Alarm_Definitions***********************/
#define RTC_AlarmDateOrWeekDaySel_Date      ((uint8_t)0x40)  
#define RTC_AlarmDateOrWeekDaySel_WeekDay   ((uint8_t)0x00)  

#define IS_RTC_Alarm_Date_WeekDay_SEL(SEL) (((SEL) == RTC_AlarmDateWeekDaySel_Date)||((SEL) == RTC_AlarmDateWeekDaySel_WeekDay))


/*******************RTC_Interrupts_Definitions*********************/ 
#define RTC_IT_RTCIE                    RTC_CR_RTCIE
#define RTC_IT_TAIE                     RTC_CR_TAIE

#define IS_RTC_ITSource(IT) (((IT) == RTC_IT_RTCIE)||((IT) == RTC_IT_TAIE))	


/**************** RTC Time structure definition ********************/
typedef struct
{
	uint8_t RTC_Hours;            //当为24小时制式                                        

	uint8_t RTC_Minutes;  					
  
	uint8_t RTC_Seconds;
	
	uint8_t RTC_H12;
	uint8_t RTC_HourFormat;
	
}RTC_TimeTypeDef; 

/**************** RTC Date structure definition *******************/
typedef struct
{
	uint8_t RTC_WeekDay;                        
  
	uint8_t RTC_Month;   				

	uint8_t RTC_Date;                           
  
	uint8_t RTC_Year;    
 
}RTC_DateTypeDef;

/*************** RTC Alarm structure definition *****************/
typedef struct
{
    FunctionalState RTC_AlarmMaskDateOrWeekDay;     //ENABLE:不需要匹配；DISABLE:需要匹配日期或星期
    FunctionalState RTC_AlarmMaskHours;             //ENABLE:不需要匹配，DISABLE:需要匹配小时
    FunctionalState RTC_AlarmMaskMinutes;           //ENABLE:不需要匹配，DISABLE:需要匹配分钟
    FunctionalState RTC_AlarmMaskSeconds;           //ENABLE:不需要匹配，DISABLE:需要匹配秒
	
	RTC_TimeTypeDef RTC_AlarmTime; 
	
	uint8_t RTC_AlarmDateOrWeekDaySel; 
 
 	uint8_t RTC_DateOrWeekDay;          
 
}RTC_AlarmTypeDef;

typedef struct
{
	uint8_t RTC_HourFormat;                       //配置时间格式
	RTC_TimeTypeDef RTC_TimeStruct;  
    RTC_DateTypeDef RTC_DateStruct; 	 
 
}RTC_InitTypeDef;

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

void RTC_DeInit(void);                                                          //RTC模块相关寄存器恢复成上电默认值
void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct);                           //初始化RTC模块，主要是设置时间和日期，不包括闹钟

void RTC_SetTime(uint8_t RTC_HourFormat, RTC_TimeTypeDef* RTC_TimeStruct);	    //设置时间,以BCD码的方式输入
void RTC_GetTime(RTC_TimeTypeDef* RTC_TimeStruct);	                            //获取RTC当前时间值，以BCD码的方式返回值

void RTC_SetDate(RTC_DateTypeDef* RTC_DateStruct);						        //设置日期，以BCD码的方式输入
void RTC_GetDate(RTC_DateTypeDef* RTC_DateStruct);	                            //获取日期，以BCD码的方式返回值

void RTC_Cmd(FunctionalState NewState);			                                //使能RTC功能

void RTC_SetAlarm(uint8_t RTC_HourFormat,RTC_AlarmTypeDef* RTC_AlarmStruct);    //设置闹钟

void RTC_AlarmCmd(FunctionalState NewState);	                                //使能闹钟功能	

void RTC_ITConfig(uint8_t RTC_IT, FunctionalState NewState);	                //配置RTC相关的中断，如闹钟中断，半秒中断

ITStatus RTC_GetITStatus(uint8_t RTC_IT);	                                    //获取相应标志位

void RTC_ClearITStatus(uint8_t RTC_IT);	                                        //清除相应标志位


#ifdef __cplusplus
}
#endif

#endif /* __SD93F115B_RTC_H */

/*****************************END OF FILE********************************/